package b.Servlet;

import b.DAO.Impl.UserDAOImpl;
import b.DAO.UserDAO;
import b.domain.User;
import b.util.DruidUtils;
import com.alibaba.druid.sql.visitor.functions.Char;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/ServletRequetDemo")
public class ServletRequetDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String email = request.getParameter("email");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        String birthday = request.getParameter("birthday");
//        JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource());
//        String sql ="insert into user values(null,?,?,?,?,?,?)";
//        template.update(sql,username,password,email,name,gender,birthday);
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setEmail(email);
        user.setName(name);
        user.setGender(gender);
        user.setBirthday(birthday);
        System.out.println(user);
        //调用DAO方法
        UserDAO userDAO = new UserDAOImpl();
        userDAO.insertUser(user);
    }
}
